package com.akk.module.user.service;

import com.akk.module.user.entity.UserCard;
import com.akk.module.user.entity.UserCardExample;
import com.akk.module.user.mapper.UserCardMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserCardService {
    @Autowired
    UserCardMapper userCardMapper;
    @Autowired
    UserCardExample userCardExample;

    public List<UserCard> findByUserId(String userId) {
        userCardExample.clear();
        userCardExample.createCriteria().andUserIdEqualTo(userId);
        return userCardMapper.selectByExample(userCardExample);
    }

    public List<UserCard> findByUserIdAndCardNum(String userId, String cardNum) {
        userCardExample.clear();
        userCardExample.createCriteria().andUserIdEqualTo(userId).andCardNumEqualTo(cardNum);
        return userCardMapper.selectByExample(userCardExample);
    }

    public void insert(UserCard userCard) {
        userCardMapper.insert(userCard);
    }


    public UserCard findByCardId(String cardId) {
        UserCard userCard = userCardMapper.selectByPrimaryKey(cardId);
        return userCard == null? new UserCard():userCard;
    }

    public void delUserCard(String cardId) {
        userCardMapper.deleteByPrimaryKey(cardId);
    }
}
